<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;

/**
 * 文档模型控制器
 * 文档模型列表和详情
 */
class ArticleController extends HomeController {

    /* 文档模型频道页 */
	public function index(){
		/* 分类信息 */
		$category = $this->category();



		//频道页只显示模板，默认不读取任何内容
		//内容可以通过模板标签自行定制
		$navid = $navid ? $navid : I('get.navid', 0);
		$this->assign('navid', $navid);

		/* 模板赋值并渲染模板 */
		$this->assign('category', $category);
        $this->setSeo($category['title']);
		$this->display($category['template_index']);
	}


  public function usearch(){
   
     foreach (I('post.') as $key => $value) {
         if($value)$map[$key]=$value;
     }


        $category = $this->category();
        $supply =M("supply");
        $sql=$supply->where($map)->select(); 

        $this->setSeo($category['title']);
        $this->assign('category', $category);
        $this->assign('supply', $sql);
        $this->display();

    }


public function supplyck(){

  $id=$_GET['id'];    
        $tab_hover = I('tab','base','trim');

        $supply = D('supply');

  

           
            $user_info =$supply->where("id='$id'")->select(); 


            if ($extend_data) {
                $user_info = array_merge($user_info,$extend_data);
            }
         

            $this->assign('tab_hover',$tab_hover);
            $this->assign('user_info',$user_info);

            $this->display();
      
    }


 public function tsearch(){
    
     foreach (I('post.') as $key => $value) {
         if($value)$map[$key]=$value;
     }


        $category = $this->category();
        $storage =M("storage");
        $sql=$storage->where($map)->select(); 

        $this->setSeo($category['title']);
        $this->assign('category', $category);
        $this->assign('storage', $sql);
        $this->display();

    }



public function storageck(){

  $id=$_GET['id'];    
        $tab_hover = I('tab','base','trim');
        $storage = D('storage');

  

           
            $user_info =$storage->where("id='$id'")->select(); 


            if ($extend_data) {
                $user_info = array_merge($user_info,$extend_data);
            }
         

            $this->assign('tab_hover',$tab_hover);
            $this->assign('user_info',$user_info);

            $this->display();
      
    }


public function ssearch(){
    
     foreach (I('post.') as $key => $value) {
         if($value)$map[$key]=$value;
     }
    

        $category = $this->category();
       $supply =M("vehicle");
        $sql=$supply->where($map)->select(); 

        $this->setSeo($category['title']);
        $this->assign('category', $category);
        $this->assign('vehicle', $sql);
        $this->display();

    }




public function vehiclck(){
$user = session('user_auth');
  $id=$_GET['id'];    
        $tab_hover = I('tab','base','trim');
        $vehicle = D('vehicle');

  

              $user_info =$vehicle->where("id='$id'")->select(); 


            if ($extend_data) {
                $user_info = array_merge($user_info,$extend_data);
            }
         

            $this->assign('tab_hover',$tab_hover);
            $this->assign('user_info',$user_info);

            $this->display();
      
    }




	/* 文档模型列表页 */
	public function lists($p = 1){
		/* 分类信息 */
		$category = $this->category();
		$navid = $navid ? $navid : I('get.navid', 0);

		$categorys = D('Category')->getChildrenId($category['id']);
		/* 获取当前分类列表 */
		$Document = D('Document');
		$list = $Document->page($p, $categorys['list_row'])->lists($categorys);
		if(false === $list){
			$this->error('获取列表数据失败！');
		}
		$model_id=1;
		if(is_array($category['model'])){
			$model_id=$category['model'][0];
		}else{
			$model_id=$category['model'];
		}
		$model=M("model")->getById($model_id,'name,title,extend');
		$this->assign('model', $model);
		$this->assign('navid', $navid);
        $this->setSeo($category['title']);
		/* 模板赋值并渲染模板 */
		$this->assign('category', $category);
		$this->assign('list', $list);
		$this->display($category['template_lists']?$category['template_lists']:$model['name']);
	}

	/* 文档模型详情页 */
	public function detail($id = 0, $p = 1){
		/* 标识正确性检测 */
		if(!($id && is_numeric($id))){
			$this->error('文档ID错误！');
		}

		/* 页码检测 */
		$p = intval($p);
		$p = empty($p) ? 1 : $p;

		/* 获取详细信息 */
		$Document = D('Document');
		$info = $Document->detail($id);
		if(!$info){
			$this->error($Document->getError());
		}

		/* 分类信息 */
		$category = $this->category($info['category_id']);

		/* 获取模板 */
		if(!empty($info['template'])){//已定制模板
			$tmpl = $info['template'];
		} elseif (!empty($category['template_detail'])){ //分类已定制模板
			$tmpl = $category['template_detail'];
		} else { //使用默认模板
			$tmpl = 'Article/'. get_document_model($info['model_id'],'name') .'/detail';
		}

		/* 更新浏览数 */
		$map = array('id' => $id);
		$Document->where($map)->setInc('view');

		/* 模板赋值并渲染模板 */
		$this->assign('category', $category);
		$this->assign('info', $info);
		$this->assign('page', $p); //页码
		$this->setSeo($info['title']);
		$this->display($tmpl);
	}
		/* 搜索 */
	public function search(){
		$search_value=$_GET[search];
	
        $m=M('document');
        $where['title']=array('like',"%$search_value%");
		/*$category=D('Category')->getChildrenId(8);
        $where['category_id']=array('in',$category);*/
        $rs=$m->where($where)->select();
  
 
        $this->assign('rs',$rs);
        $this->display();
	}
	/* 联合搜索开始 */
	public function search_show_table($model_id=0){
		if(!is_null($model_id)){
			$model_connect=M('model');
			$model=$model_connect->find($model_id);//读取当前model参数
			$search_list=$model['search_list'];//搜索参数

			$attribute_connect=M('attribute');
			$map['model_id']=$model_id;//读取当前model存在的字段
			$map['name']=array('IN',$search_list);
			$attribute=$attribute_connect->field('id,name,title,type,extra')->where($map)->select();
			$this->assign('attr',$attribute);
			$this->display();
		}
	}
	public function union_search(){
		$data=json_decode(I('data'));
		$table=json_decode(I('table'));
		$model_id=I('model_id');
		$map=array();
		foreach ($table as $key => $value) {
			if($data[$key])
				$map[$value]=$data[$key];
		}
		//$m=M('document_product')->where($map)->select(false);
		//$list=$this->getDocumentList($map,$model_id);
		//var_dump($list);
		//var_dump($map);
		$Document = M('Document');
	    $Document->alias('DOCUMENT');
	    $map['model_id']    =   $model_id;
	    $modelName  =   M('Model')->getFieldById($model_id,'name');
	    $Document->join('__DOCUMENT_'.strtoupper($modelName).'__ '.$modelName.' ON DOCUMENT.id='.$modelName.'.id');
	    $field = 'DOCUMENT.id as mainid,DOCUMENT.*,'.$modelName.'.*';
	    $Document->where($map);
	    $doc=clone $Document;
		$total=$doc->count();

		$_GET['p']=3;
	    $listRows = C('LIST_ROWS') > 0 ? C('LIST_ROWS') : 10;
	    $page = new \Think\Page($total, $listRows, $_GET);
	    if($total>$listRows){
	        $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
	    }
	    $p =$page->show();
	    $this->assign('_page', $p? $p: '');
	    $this->assign('_total',$total);
	    $limit = $page->firstRow.','.$page->listRows;



		$list=$Document->field($field)->limit($limit)->select();
		$this->assign('list',$list);
		$template=I('template')?I('template'):"default";
		$this->display($template);
		//var_dump($list);
	}





	/* 业务种类*/
	public function Business(){
		$User = M('bucopr');
		$verify=$_POST['verify'];
		if(!check_verify($verify)){
			echo false;
		}else{
			$data["name"]=$_POST["hidden"];
			$data["company"]=$_POST["Company"];
			$data["contact"]=$_POST["contact"];
			$data["phone"]=$_POST["phone"];
			$data["addtime"]=time();
			if($User->add($data)){
				echo true;
			}else{
				echo false;
			}
		}
        //$this->display();
	}
	/* 业务种类*/
	public function ajax_tt(){
		$suffix=explode(",",$_GET['suffix']);
		foreach ($suffix as $key => $value) {
			$url = 'http://panda.www.net.cn/cgi-bin/check.cgi?area_domain='.$_GET['domain'].$value; 
			$contents = file_get_contents($url); 
			$xml = simplexml_load_string($contents);
			if (!empty($xml)) {
				$status=  substr($xml->original,0,3);
				$result;
				if($status=="210"){
					$result='可以注册';
				}else if($status=="211"){
					$result='已经注册';
				}else if($status=="212"){
					$result='参数错误';
				}
			}else{
				$result='域名错误';
			}
			$domain[$key]['url']=$_GET['domain'].$value;
			$domain[$key]['type']=$result;
		}
		$category = $this->category();
		$this->assign("category",$category);
		$this->assign("domain",$domain);
        $this->display();
	}

}
